﻿//volidate
function volidateConInfo() {
    $("#ContentPlaceHolder2_lblMeg").html("");
    $(".Warning").html("");
    $(".form-table input[type='text']").attr("style", "");
    var Rnum = RegExp('^[0-9 ]{1,}$');
    var Rmai = RegExp('^^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$');
    var regMail = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    var RSite = RegExp('^http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$');
    var Arr = new Array("Country Code", "Area Code", "Telephone No.", "example@example.com","http://www.example.com");
    var status = true;
    //alert(jQuery.inArray("Area Code", Arr));
    var msgN = "请输入合法的号码";
    var msgEmail = "Please input valid format: Example@expamle.com";
    var msgWebSite = "Please input valid format: http://www.example.com";
    var msgNull = "";

    //找到不隐藏的表单组，实行验证
    var obj = [];
    obj = $("#phone-wrap").find(".activityWrap");
    obj.each(function (i) {
        var self = $(this);
        var dis = self.css("display")
        if (dis == "block") {
            self.find("input[type='text']").each(function () {
                var selfs = $(this);
                var vals = selfs.val();
                if (Rnum.test(vals) || jQuery.inArray(vals, Arr) != -1) {
                    selfs.css("border", " ");
                    //selfs.parents(".activityWrap").find(".Warning").text(msgNull);
                }
                else {
                    selfs.css("border", "1px solid red");
                    //alert(selfs.parents(".activityWrap").find(".Warning"));
                    selfs.parents(".activityWrap").find(".Warning").text(msgN);
                    status = false;
                }

            })
        } else {
            self.find("input[type='text']").each(function () {
                $(this).css("border", " ");
                self.find(".Warning").text(msgNull);
            })

        }
    });


    obj = $("#fax-wrap").find(".activityWrap");
    obj.each(function (i) {
        var self = $(this);
        var dis = self.css("display")
        if (dis == "block") {
            self.find("input[type='text']").each(function () {
                var selfs = $(this);
                var vals = selfs.val();
                if (Rnum.test(vals) || jQuery.inArray(vals, Arr) != -1) {
                    selfs.css("border", " ");
                    //selfs.parents(".activityWrap").find(".Warning").text(msgNull);
                }
                else {
                    selfs.css("border", "1px solid red");
                    selfs.parents(".activityWrap").find(".Warning").text(msgN);
                    status = false;
                }

            })
        } else {
            self.find("input[type='text']").each(function () {
                $(this).css("border", " ");
                self.find(".Warning").text(msgNull);
            })

        }
    });
    obj = $("#web-wrap").find(".activityWrap");
    obj.each(function (i) {
        var self = $(this);
        var dis = self.css("display")
        if (dis == "block") {
            self.find("input[type='text']").each(function () {
                var selfs = $(this);
                var vals = selfs.val();
                if (RSite.test(vals) || jQuery.inArray(vals, Arr) != -1) {
                    selfs.css("border", " ");
                    //selfs.parents(".activityWrap").find(".Warning").text(msgNull);
                }
                else {
                    selfs.css("border", "1px solid red");
                    selfs.parents(".activityWrap").find(".Warning").text(msgWebSite);
                    status = false;
                }

            })
        } else {
            self.find("input[type='text']").each(function () {
                $(this).css("border", " ");
                self.find(".Warning").text(msgNull);
            })

        }
    });
    obj = $("#email-wrap").find(".activityWrap");
    obj.each(function (i) {
        var self = $(this);
        var dis = self.css("display")
        if (dis == "block") {
            self.find("input[type='text']").each(function () {
                var selfs = $(this);
                var vals = selfs.val();
                //if (Rmai.test(vals) || jQuery.inArray(vals, Arr) != -1) {
                if (vals.match(regMail) && vals != "") {
                    selfs.css("border", " ");
                }
                else {
                    selfs.css("border", "1px solid red");
                    selfs.parents(".activityWrap").find(".Warning").text(msgEmail);
                    status = false;
                }

            })
        } else {
            self.find("input[type='text']").each(function () {
                $(this).css("border", "  ");
                self.find(".Warning").text(msgNull);
            })
        }
    });

    if (status == true) {
        $(".activity-phnone .Warning").html("");
        $(".activity-phnone").find("input[type='text']").css("border", "");
    }
    return status;

}

// pop dele form
function delete_confirms(id, fun, obj) {
    var argstr = [];
    argstr = id.split('_');

    if (argstr[1] != null)
        args1 = argstr[1];

    idbox = argstr[0];
    $("#" + idbox).PopupDiv({
        PopupDivId: "PopupDiv" + id,
        title: "",
        modal: true,
        //left: document.documentElement.scrollLeft + 500,
        top: document.documentElement.scrollTop + 200

    });
    RegisFun = fun;
    objs = obj;
}
function SureDelete() {
    //deal the function
    if (RegisFun != "" && RegisFun != null)
        eval(RegisFun + "()");

    //hidden the popdiv
    $("#DeleteBox").PopupDiv("remove");
}

function CloseDelete() {
    //$(".close_out").click();
    $("#DeleteBox").PopupDiv("remove");
}

//quit
function DoDeleteQ() {
    $(".myTi_r close_out").click();
}
// do delete action
function DoDeleteS() {
    delModelTelephone(objs);
    $("#DeleteBox").PopupDiv("remove");
}


//teletephone
function addModelTelephone(arg) {

    var ParN = $("#phone-wrap");

    var obj = [];
    obj = ParN.find(".activityWrap");
    for (i = 0; i < 5; i++) {
        if ($(obj[i]).css("display") == "none") {
            $(obj[i]).css("display", "block");
            $(obj[i]).find("input[type='text']").each(function () {
                $(this).focus();
                $(this).blur();
            });
            if (i == 4) {
                $("#phone-wrap .addimg").hide();
            }
            break;
        }
    }

}
function evalfn() {
    //alert("s");
}

function delModelTelephone(arg, cc) {
    if (arg == "undefind" || arg == null)
        arg = objs;

    $(arg).parents(".parnt").find(".addimg").show();
    $(arg).parents(".activityWrap").hide();
    $(arg).parents(".activity-phnone").find("input[type='text']").val("");
    $(arg).parents(".activity-phnone").find("input[type='text']").each(function () {
        $(this).focus();
        $(this).blur();
    });
}

//fax
function addModelFax(arg) {
    var ParN = $("#fax-wrap");

    var obj = [];
    obj = ParN.find(".activityWrap");
    for (i = 0; i < 5; i++) {
        if ($(obj[i]).css("display") == "none") {
            $(obj[i]).css("display", "block");
            $(obj[i]).find("input[type='text']").each(function () {
                $(this).focus();
                $(this).blur();
            });
            if (i == 4) {
                $("#fax-wrap .addimg").hide();
            }
            break;
        }
    } 
}
function delModelFax(arg) {

    if (arg == "undefind" || arg == null)
        arg = objs;

    $(arg).parents(".parnt").find(".addimg").show();
    $(arg).parents(".activityWrap").hide();
    $(arg).parents(".activity-phnone").find("input[type='text']").val("");
}



//Email 
function addModelEmail() {
    var ParN = $("#email-wrap");

    var obj = [];
    obj = ParN.find(".activityWrap");
    for (i = 0; i < 5; i++) {
        if ($(obj[i]).css("display") == "none") {
            $(obj[i]).css("display", "block");
            $(obj[i]).find("input[type='text']").each(function () {
                $(this).focus();
                $(this).blur();
            });
            if (i == 4) {
                $("#email-wrap .addimg").hide();
            }
            break;
        }
    }
}
function delModelEmail(arg) {
    if (arg == "undefind" || arg == null)
        arg = objs;
    $(arg).parents(".parnt").find(".addimg").show();
    $(arg).parents(".activityWrap").hide();
    $(arg).parents(".activity-phnone").find("input[type='text']").val("");
}

//web
function addModelWeb(arg) {
    var ParN = $("#web-wrap");

    var obj = [];
    obj = ParN.find(".activityWrap");
    for (i = 0; i < 2; i++) {
        if ($(obj[i]).css("display") == "none") {
            $(obj[i]).css("display", "block");
            $(obj[i]).find("input[type='text']").each(function () {
                $(this).focus();
                $(this).blur();
            });
            if (i == 4) {
                $("#web-wrap .addimg").hide();
            }
            break;
        }
    }
}


function delModelWeb(arg) {
    if (arg == "undefind" || arg == null)
        arg = objs;
    $(arg).parents(".parnt").find(".addimg").show();
    $(arg).parents(".activityWrap").hide();
    $(arg).parents(".activity-phnone").find("input[type='text']").val("");
}